package cn.com.bdqn.controller;

import cn.com.bdqn.entity.CstCustomer;
import cn.com.bdqn.entity.CstLost;
import cn.com.bdqn.entity.Orders;
import cn.com.bdqn.service.CstLostService;
import cn.com.bdqn.utils.ReturnData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cstLost")
@Api(tags = "客户流失管理接口")
public class CstLostController {

    @Autowired
    private CstLostService cstLostService;

    @Operation(summary = "客户流失高级查询")
    @PostMapping("/queryByLike")
    public ReturnData queryByLike(String custManagerName, String custName, String lstStatus, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "15") int pageSize){
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Map> mapList = cstLostService.queryByLike(custManagerName,custName,lstStatus);
            PageInfo pageInfo = new PageInfo(mapList,3);
            return ReturnData.ok().put("mapList",mapList).put("pageInfo",pageInfo);
        }catch (Exception e){
            return ReturnData.currError("数据库异常");
        }
    }

    @Operation(summary = "根据客户流失编号查询单个客户流失信息")
    @PostMapping("/queryByLstId")
    public ReturnData queryByLstId(Long lstId){
        try {
            Map map = cstLostService.queryByLstId(lstId);
            return ReturnData.ok().put("map",map);
        }catch (Exception e){
            return ReturnData.currError("数据库异常");
        }
    }

    @Operation(summary = "修改客户流失信息")
    @PostMapping("/updateCstLost")
    public ReturnData updateCstLost(CstLost cstLost){
        int result = cstLostService.updateCstLost(cstLost);
        if (result > 0){
            return ReturnData.ok();
        }else {
            return ReturnData.error();
        }
    }

}
